package com.mall.pay.service.impl;

import com.mall.pay.model.PayLog;
import com.mall.pay.mapper.PayLogMapper;
import com.mall.pay.service.IPayLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Darren
 * @since 2022-09-13
 */
@Service
public class PayLogServiceImpl extends ServiceImpl<PayLogMapper, PayLog> implements IPayLogService {
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean addPayLog(PayLog paylog){
        return super.save(paylog);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean deleteById(String id){
        return super.removeById(id);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean updatePayLog(PayLog paylog){
        return super.updateById(paylog);
    }

    @Override
    public PayLog getById(String id){
        return super.getById(id);
    }

    @Override
    public List<PayLog> selectList(PayLog paylog){
        return super.list(getQueryWrapper(paylog));
    }

    @Override
    public Page<PayLog> selectPage(Page<PayLog> page, PayLog paylog){
        return super.page(page, getQueryWrapper(paylog));
    }

    public LambdaQueryWrapper<PayLog> getQueryWrapper(PayLog paylog){
        return Wrappers.<PayLog>lambdaQuery()
            .eq(ObjectUtils.isNotEmpty(paylog.getId()), PayLog::getId, paylog.getId())
            .eq(ObjectUtils.isNotEmpty(paylog.getStatus()), PayLog::getStatus, paylog.getStatus())
            .eq(ObjectUtils.isNotEmpty(paylog.getContent()), PayLog::getContent, paylog.getContent())
            .eq(ObjectUtils.isNotEmpty(paylog.getPayId()), PayLog::getPayId, paylog.getPayId())
        ;
    }
}
